package tp_lab1_liczba;

public class Liczba {

	private int dec;

	public String convertFromDec(int base) throws WrongNumberException {

		if (dec <0)
			throw new WrongNumberException();
		if (base < 2 || base > 16)
			throw new WrongNumberException();
		String bin = "";
		String binTemp = "";
		if (dec == 0)
			bin = "0";
		else {
			while (dec != 0) {
				if (dec % base == 0)
					binTemp = binTemp + "0";
				else if (dec % base == 1)
					binTemp = binTemp + "1";
				else if (dec % base == 2)
					binTemp = binTemp + "2";
				else if (dec % base == 3)
					binTemp = binTemp + "3";
				else if (dec % base == 4)
					binTemp = binTemp + "4";
				else if (dec % base == 5)
					binTemp = binTemp + "5";
				else if (dec % base == 6)
					binTemp = binTemp + "6";
				else if (dec % base == 7)
					binTemp = binTemp + "7";
				else if (dec % base == 8)
					binTemp = binTemp + "8";
				else if (dec % base == 9)
					binTemp = binTemp + "9";
				else if (dec % base == 10)
					binTemp = binTemp + "A";
				else if (dec % base == 11)
					binTemp = binTemp + "B";
				else if (dec % base == 12)
					binTemp = binTemp + "C";
				else if (dec % base == 13)
					binTemp = binTemp + "D";
				else if (dec % base == 14)
					binTemp = binTemp + "E";
				else
					binTemp = binTemp + "F";
				dec = dec / base;
			}
			for (int i = binTemp.length(); i > 0; i--) {
				bin = bin + binTemp.substring(i - 1, i);
			}
		}
		return bin;
	}

	public int getDec() {
		return dec;
	}

	public void setDec(int dec) {
		this.dec = dec;
	}
}